package com.mumu.studykotlin

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import kotlinx.android.synthetic.main.activity_basal.*

class BasalActivity : AppCompatActivity() {

    companion object {
        fun start(context: Context) {
            context.startActivity(Intent(context, BasalActivity::class.java))
        }
    }

    private val contents = arrayListOf("变量", "函数", "重载")

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_basal)
        list_rv.layoutManager = LinearLayoutManager(this)
        list_rv.adapter = BasicListAdapter(contents)
    }


    class BasicListAdapter(var data: List<String>) : RecyclerView.Adapter<BasicListAdapter.BasicViewHolder>() {
        override fun getItemCount(): Int = data.size

        override fun onBindViewHolder(holder: BasicViewHolder, position: Int) {
            val s = data[position]
            holder.basicTv.text = s
        }

        override fun onCreateViewHolder(p0: ViewGroup, p1: Int): BasicViewHolder {
            val view = LayoutInflater.from(p0.context).inflate(R.layout.item_basic, p0, false)
            return BasicViewHolder(view)
        }

        inner class BasicViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
            var basicTv: TextView = itemView.findViewById(R.id.basic_tv)

        }
    }
}
